package de.koller.gravity.scene.fog;

import de.koller.aframe.plain.rasterOperations.RasterOperations;
import de.koller.aframe.util.misc.ColorGradient;
import de.koller.aframe.util.resource.IOLoader;
import de.koller.gravity.scene.Scene;
import de.koller.oceanFramework.gl.util.ImagePreview;
import de.koller.oceanFramework.gl.util.RasterManager;
import java.awt.image.BufferedImage;
import java.util.Random;

public class FogScene extends Scene {
	public Random rnd = new Random();
	public int width = 1000;
	public int height = 500;
	
	public static void main( String[] args ) {
		FogScene f = new FogScene();
		ImagePreview.showImage( f.renderScene(), f.width, f.height );
	}
	
	@Override
	public BufferedImage renderScene() {
		return renderScene( 0 );
	}
	
	public BufferedImage renderScene( int frame ) {
		System.out.println( "render frame: " + frame );
		
		RasterManager r = new RasterManager( width, height );
		
		for( int x = 0; x < width; x++ )
			for( int y = 0; y < height; y++ ) {
				r.setPixel( 0xff000000, x, y );
			}
	
		RasterOperations.add( r, getSpotLight(), 0, 0 );
		return IOLoader.create( r );
	}
	
	private RasterManager getSpotLight() {
		RasterManager r = new RasterManager( 1000, 500 );
		r.clear( 0xff000000 );
		
		for( int x = 0; x < 1000; x++ )
			for( int y = 0; y < 500; y++ ) {
				float dm = Math.abs( 250 - y );
				float mm = 250f/1000f * x;
				
				if( mm < dm )
					continue;
				
				int mc = ColorGradient.cubic( 1f/1000f * x, 0xff_ffffff, 0xff_000000 );
				int c = ColorGradient.cubic( 1f/mm * dm, mc, 0xff_000000 );
				r.setPixel( c, x, y );
			}
		
		return r;
	}
	
}
